<template>
  <main>
    <!-- is 传入注册的组件的名称或者传入一个Promise对象返回的组件对象 -->
    <component :is="getComponent()" title="我是标题" @input="(v) => subValue = v"></component>
    <p>{{subValue}}</p>
    <button @click="com++">点击切换</button>
  </main>
</template>

<script>
import HelloWorld from "./components/01hello/hello-world.vue";
import HelloIndex from "./components/01hello/hello-index.vue";

export default {
  name: "App",
  components: {
    // HelloWorld,HelloIndex
  },
  data() {
    return {
      com: 0,
      subValue: ''
    };
  },
  methods: {
    getComponent() {
      if (this.com % 2 == 0) {
        return HelloWorld;
      } else {
        return HelloIndex;
      }
    },
  },
};
</script>

<style>
* {
  padding: 0px;
  margin: 0px;
  list-style: none;
  text-decoration: none;
  box-sizing: border-box;
}
</style>
